setwd("E:\\5hmc_file\\2_5hmc_yjp_bam\\ASM\\20210324.eQTL和mQTL富集结果")
library(openxlsx)
library(ggplot2)

gtex=read.csv("GTEx.eQTL/zong.GTEx.eQTL..enrich.random1.csv",header = T)
LIBD=read.csv("LIBD.eQTL/LIBD.eQTL.enrich.random1.csv",header = T)
meqtl=read.csv("mQTL.result/zong.mQTL.enrich.random1.csv",header = T)

file1=rbind(gtex[5,],LIBD[5,],meqtl[5,])
file1$group1=c("GTEx.eQTL","LIBD.eQTL","meQTL")
file1=file1[order(file1$P.value),]
file1$num=dim(file1)[1]:1

ggplot(data=file1,aes(x=num,y=OR,fill= P.value))+scale_x_continuous(breaks = file1$num,labels = file1$group1)+
  geom_bar(stat="identity") + coord_flip()+
  theme(panel.background=element_rect(fill='transparent',color='gray'),axis.text.y=element_text(color="black",size=15),axis.text.x=element_text(color="black",size=15))+
  scale_fill_gradient(low="#E64B35",high="#3C5488")+
  labs(x="Term",y="OR",title="")


sel1=list.files(pattern = "enrich.random1.csv",path = "./GTEx.eQTL/",full.names = T)[-12]
i=1
for(i in 2:length(sel1)){
  tmp=read.csv(sel1[i],header = T)[5,]
  fn=gsub("./GTEx.eQTL/GTEx.eQTL.","",sel1[i])
  fn=gsub(".enrich.random1.csv","",fn)
  tmp$group=fn
  ft=rbind(ft,tmp)
}
ft$logP.value=-log10(ft$P.value)
ft=ft[order(ft$OR,decreasing = T),]
ft$num=dim(ft)[1]:1


##dot
ggplot(ft,aes(OR,num))+geom_point(aes(size=overlap.num,color=P.value))+
  scale_color_gradient(low = "#E64B35", high = "#3C5488")+
  scale_y_continuous(breaks = ft$num,labels = ft$group)+
  theme_bw()+
  theme(panel.grid.minor = element_blank(),axis.text = element_text(size = 12))

LIBD1=read.csv("LIBD.eQTL/tissue.DLPFC.LIBD.eQTL.enrich.random1.csv",header = T)[5,]
LIBD2=read.csv("LIBD.eQTL/tissue.HIPPO.LIBD.eQTL.enrich.random1.csv",header = T)[5,]
#LIBD3=read.csv("LIBD.eQTL/tissue.Interaction.LIBD.eQTL.enrich.random1.csv",header = T)[5,]
LIBD1$group="DLPFC"
LIBD2$group="HIPPO"
#LIBD3$group="Interaction"
rt=rbind(LIBD1,LIBD2)
rt$num=2:1
ggplot(data=rt,aes(x=num,y=OR,fill= P.value))+scale_x_continuous(breaks = rt$num,labels = rt$group)+
  geom_bar(stat="identity") + coord_flip()+
  theme(panel.background=element_rect(fill='transparent',color='gray'),axis.text.y=element_text(color="black",size=15),axis.text.x=element_text(color="black",size=15))+
  scale_fill_gradient(low="#E64B35",high="#3C5488")+
  labs(x="Term",y="OR",title="")




###bar
ggplot(data=file1,aes(x=num,y=enrichmentRatio,fill=FDR))+scale_x_continuous(breaks = file1$num,labels = file1$description)+
  geom_bar(stat="identity") + coord_flip()+
  theme(panel.background=element_rect(fill='transparent',color='gray'),axis.text.y=element_text(color="black",size=15),axis.text.x=element_text(color="black",size=15))+
   scale_fill_gradient(low="red",high="blue")+
  labs(x="term",y="enrichmentRatio",title="")

